package com.viethp.mt.activities;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.List;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.viethp.mt.activities.R;
import com.viethp.mt.common.CommonHelper;
import com.viethp.mt.common.GlobalVariables;
import com.viethp.mt.common.HttpFileUploader;
import com.viethp.mt.common.MyLocationListener;
import com.viethp.mt.mapoverlay.MyItemizedOverlay;
import com.viethp.mt.objects.AddPostResponse;
import com.viethp.mt.objects.Position;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnticipateOvershootInterpolator;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.ArrayWheelAdapter;

public class APostItemDetails extends MapActivity implements OnClickListener {

	ImageView img_post_img;
	private static final int REQUEST_GALLERY = 1336;
	private static final int REQUEST_CAMERA = 1337;
	private static final int REQUEST_TITLE = 1111;

	private TextView tv_post_title, tv_post_price, tv_post_exp, tv_post_desc,
			tv_post_category;
	private EditText edt_title;
	private Button btn_post;
	private String post_title, post_price, post_desc;
	private int post_exp, post_category;

	private Bitmap selectedAvatar, bitmap;
	private int status;
	private Drawable d;
	
	MapController mControl;
	GeoPoint GeoP;
	MapView mapV;
	private Drawable items;
	private List<Overlay> mapOverlays;
	private MyItemizedOverlay itemizedOverlay;

	private ProgressDialog progressDialog;

	private String[] exp_hours_list_array = new String[] { "0", "1", "2", "3",
			"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
			"16", "17", "18", "19", "20", "21", "22", "23" };
	private String[] exp_days_list_array = new String[] { "0", "1", "2", "3",
			"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
			"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
			"27", "28", "29", "30" };
	private String[] exp_mons_list_array = new String[] { "0", "1", "2", "3" };
	private String[] category_list_array = new String[] { "Mobile phone",
			"Household electrical appliances", "Computer",
			"Telecommunications equipment" };
	String imageSrc;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.a_post_item_details);
		
		mapV = (MapView) findViewById(R.id.mapView);
		mapV.displayZoomControls(true);
		mapV.setBuiltInZoomControls(true);

		mapV.setTraffic(true);
		mapV.setPressed(false);
		mapV.setClickable(false);

		initComponents();
		setOnClickListener();
		setPosition();
		setMap();
	}

	public void initComponents() {
		img_post_img = (ImageView) findViewById(R.id.img_post_image);

		d = this.getResources().getDrawable(R.drawable.ic_post_image);
		bitmap = ((BitmapDrawable) d).getBitmap();
		img_post_img.setImageBitmap(CommonHelper.getRoundedCornerBitmap(bitmap,
				APostItemDetails.this));

		tv_post_title = (TextView) findViewById(R.id.tv_post_title);
		tv_post_price = (TextView) findViewById(R.id.tv_post_price);
		tv_post_exp = (TextView) findViewById(R.id.tv_post_exp);
		tv_post_desc = (TextView) findViewById(R.id.tv_post_desc);
		tv_post_category = (TextView) findViewById(R.id.tv_post_category);

		btn_post = (Button) findViewById(R.id.btn_post);

		status = 0;
		post_exp = 0;
		post_category = 0;
		post_title = "";
		post_price = "";
		post_desc = "";
		progressDialog = new ProgressDialog(APostItemDetails.this);
		progressDialog.setCancelable(false);
	}

	public void setOnClickListener() {
		img_post_img.setOnClickListener(this);
		tv_post_title.setOnClickListener(this);
		tv_post_price.setOnClickListener(this);
		tv_post_exp.setOnClickListener(this);
		tv_post_desc.setOnClickListener(this);
		tv_post_category.setOnClickListener(this);

		btn_post.setOnClickListener(this);
	}

	private WheelView initWheel(int id, String[] values, View view) {
		WheelView wheel = (WheelView) view.findViewById(id);
		ArrayWheelAdapter<String> adapter = new ArrayWheelAdapter<String>(this,
				values);
		adapter.setTextSize(20);
		wheel.setViewAdapter(adapter);
		wheel.setCurrentItem(1);
		wheel.setCyclic(true);
		wheel.setInterpolator(new AnticipateOvershootInterpolator());

		return wheel;
	}

	protected Dialog showDialogAddImage() {

		final CharSequence[] items = { "Take a picture", "Pick from gallery" };
		return new android.app.AlertDialog.Builder(this)
				.setTitle(getString(R.string.post_add_image))
				.setItems(items, new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int item) {
						if (item == 1) {
							CommonHelper.callGallery(APostItemDetails.this,
									REQUEST_GALLERY);

						} else if (item == 0) {
							String oXY = String.valueOf(CommonHelper.dptopx(
									(float) 120, APostItemDetails.this));
							Intent cameraIntent = new Intent(
									android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
							cameraIntent.putExtra("outputX", oXY);
							cameraIntent.putExtra("outputY", oXY);
							cameraIntent.putExtra("aspectX", 0);
							cameraIntent.putExtra("aspectY", 0);
							cameraIntent.putExtra("scale", true);
							cameraIntent.putExtra("return-data", true);
							try {

								startActivityForResult(cameraIntent,
										REQUEST_CAMERA);
							} catch (ActivityNotFoundException e) {
								// Do nothing for now
							}
						}
					}
				})
				.setNegativeButton("Cancel",
						new DialogInterface.OnClickListener() {
							public void onClick(
									android.content.DialogInterface dialog,
									int whichButton) {

							}
						}).create();
	}

	public void DialogTitle() {

		LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		final View view = layoutInflater.inflate(R.layout.dialog_post_input,
				null);
		edt_title = (EditText) view.findViewById(R.id.edt_post_input);
		InputFilter[] FilterArray = new InputFilter[1];
		FilterArray[0] = new InputFilter.LengthFilter(20);
		edt_title.setFilters(FilterArray);

		final Dialog dia = new Dialog(this);
		dia.setContentView(view);
		dia.setTitle("Enter Title");
		dia.getWindow().setLayout(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);
		dia.setCancelable(false);
		dia.show();

		final Button btn_change = (Button) view.findViewById(R.id.btn_change);
		if (String.valueOf(edt_title.getText()).equals(""))
			btn_change.setEnabled(false);
		edt_title.addTextChangedListener(new TextWatcher() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
				if (String.valueOf(edt_title.getText()).trim().equals("")
						|| String.valueOf(edt_title.getText()).trim().length() < 6)
					btn_change.setEnabled(false);
				else
					btn_change.setEnabled(true);
			}
		});

		btn_change.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				post_title = edt_title.getText().toString().trim();
				tv_post_title.setText(post_title);
				dia.dismiss();
			}
		});
		Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
		btn_cancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dia.dismiss();

			}
		});
	}

	public void DialogPrice() {

		LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		final View view = layoutInflater.inflate(R.layout.dialog_post_input,
				null);
		edt_title = (EditText) view.findViewById(R.id.edt_post_input);
		edt_title.setInputType(InputType.TYPE_CLASS_NUMBER);

		final Dialog dia = new Dialog(this);
		dia.setContentView(view);
		dia.setTitle("Enter Price");
		dia.getWindow().setLayout(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);
		dia.setCancelable(false);
		dia.show();

		final Button btn_change = (Button) view.findViewById(R.id.btn_change);
		if (String.valueOf(edt_title.getText()).equals(""))
			btn_change.setEnabled(false);
		edt_title.addTextChangedListener(new TextWatcher() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
				if (String.valueOf(edt_title.getText()).trim().equals(""))
					btn_change.setEnabled(false);
				else
					btn_change.setEnabled(true);
			}
		});

		btn_change.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				post_price = edt_title.getText().toString().trim();
				tv_post_price.setText("$"+post_price);
				dia.dismiss();
			}
		});
		Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
		btn_cancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dia.dismiss();

			}
		});
	}

	public void DialogEXP() {
		LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		final View view = layoutInflater.inflate(R.layout.dialog_exp, null);
		final WheelView mon = initWheel(R.id.exp_mons, exp_mons_list_array,
				view);
		final WheelView day = initWheel(R.id.exp_days, exp_days_list_array,
				view);
		final WheelView hour = initWheel(R.id.exp_hours, exp_hours_list_array,
				view);

		final Dialog dia = new Dialog(this);
		dia.setContentView(view);
		dia.setTitle("choose EXP");
		dia.getWindow().setLayout(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);
		dia.setCancelable(false);
		dia.show();

		final Button btn_change = (Button) view.findViewById(R.id.btn_change);
		btn_change.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				int mons = mon.getCurrentItem();
				int days = day.getCurrentItem();
				int hours = hour.getCurrentItem();
				long exp = CommonHelper.toSecond(mons, days, hours);
				post_exp = (int) exp;
				String exp_left = CommonHelper.timeLeft(exp);
				tv_post_exp.setText(String.valueOf(exp_left));
				dia.dismiss();
			}
		});
		Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
		btn_cancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dia.dismiss();

			}
		});
	}

	public void DialogDesc() {
		LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		final View view = layoutInflater.inflate(R.layout.dialog_post_input,
				null);
		edt_title = (EditText) view.findViewById(R.id.edt_post_input);

		final Dialog dia = new Dialog(this);
		dia.setContentView(view);
		dia.setTitle("Enter Description");
		dia.getWindow().setLayout(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);
		dia.setCancelable(false);
		dia.show();

		final Button btn_change = (Button) view.findViewById(R.id.btn_change);
		if (String.valueOf(edt_title.getText()).equals(""))
			btn_change.setEnabled(false);
		edt_title.addTextChangedListener(new TextWatcher() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
				if (String.valueOf(edt_title.getText()).trim().equals(""))
					btn_change.setEnabled(false);
				else
					btn_change.setEnabled(true);
			}
		});

		btn_change.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				post_desc = edt_title.getText().toString().trim();
				tv_post_desc.setText(post_desc);
				dia.dismiss();
			}
		});
		Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
		btn_cancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dia.dismiss();

			}
		});
	}

	public void DialogCategory() {
		LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		final View view = layoutInflater.inflate(R.layout.dialog_wheel, null);
		final WheelView category = initWheel(R.id.wheel_dialog,
				category_list_array, view);

		final Dialog dia = new Dialog(this);
		dia.setContentView(view);
		dia.setTitle("Choose category");
		dia.getWindow().setLayout(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);
		dia.setCancelable(false);
		dia.show();

		final Button btn_change = (Button) view.findViewById(R.id.btn_change);
		btn_change.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				post_category = category.getCurrentItem() + 1;
				tv_post_category
						.setText(category_list_array[post_category - 1]);
				dia.dismiss();
			}
		});
		Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
		btn_cancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dia.dismiss();

			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.img_post_image:
			showDialogAddImage().show();
			break;
		case R.id.tv_post_title:
			DialogTitle();
			break;
		case R.id.tv_post_price:
			DialogPrice();
			break;
		case R.id.tv_post_exp:
			DialogEXP();
			break;
		case R.id.tv_post_desc:
			DialogDesc();
			break;
		case R.id.tv_post_category:
			DialogCategory();
			break;
		case R.id.btn_post:
			if (checkValid()) {
				if (status != 1) {
					CommonHelper.showWarning(this, "Please attach an image!");
				} else
					doUpload();
			}

			break;
		}
	}

	public boolean checkValid() {
		if (post_title.equals("")) {
			CommonHelper.showWarning(this, "Please input title!");
			return false;
		} else if (post_exp == 0) {
			CommonHelper.showWarning(this, "Please choose exp!");
			return false;
		} else if (post_price.equals("")) {
			CommonHelper.showWarning(this, "Please input price!");
			return false;
		} else if (post_category == 0) {
			CommonHelper.showWarning(this, "Please choose category");
			return false;
		}
		return true;
	}

	public void onActivityResult(int requestCode, int resultCode, Intent data) {

		if (resultCode == RESULT_OK) {

			if (requestCode == REQUEST_GALLERY) {
				Uri currImageURI = data.getData();
				try {
					InputStream in = getContentResolver().openInputStream(
							currImageURI);

					selectedAvatar = BitmapFactory.decodeStream(in);
					img_post_img.setImageBitmap(CommonHelper
							.getRoundedCornerBitmapGallery(selectedAvatar));
					status = 1;

				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
			if (requestCode == REQUEST_CAMERA) {
				try {

					selectedAvatar = (Bitmap) data.getExtras().get("data");
					img_post_img.setImageBitmap(CommonHelper
							.getRoundedCornerBitmap(selectedAvatar,
									APostItemDetails.this));
					status = 1;

				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
			if (requestCode == REQUEST_TITLE) {
				String d = data.getStringExtra("TITLE");
				tv_post_title.setText(d);
			}
		}
	}

	private int UpImage(Bitmap bm) {
		String imgName = String.valueOf(CommonHelper.getCurrentDate()) + ".PNG";
		try {
			ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
			if ((bm.getHeight() < 367) && bm.getWidth() < 320)
				bm.compress(CompressFormat.PNG, 75, bos1);
			else {
				int hs = 367;
				int ws = 320;
				if (bm.getWidth() < ws)
					ws = bm.getWidth();
				if (bm.getHeight() < hs)
					hs = bm.getHeight();
				CommonHelper.getResizedBitmap(bm, ws, hs).compress(
						CompressFormat.PNG, 75, bos1);
			}

			byte[] data1 = bos1.toByteArray();
			HttpFileUploader t1 = new HttpFileUploader(
					GlobalVariables.UPLOAD_URL, imgName, data1, "");
			if (t1.doUpload().toString().equals("")) {
				imageSrc = GlobalVariables.UPLOAD_URLIMAGE + imgName;
				Log.d("IMG", "1");
				return GlobalVariables.ReOK;
			}
		} catch (Exception e) {
			Log.d("IMG", "2");
			return GlobalVariables.ReFail;
		}
		return GlobalVariables.ReOK;
	}

	private void doUpload() {
		if (CommonHelper.isNetworkAvailable(this)) {
			startCallServiceUpload();
		} else
			CommonHelper.showWarning(APostItemDetails.this,
					getString(R.string.netstate));
	}

	public void startCallServiceUpload() {
		progressDialog.setMessage(getString(R.string.pleasewait));
		progressDialog.show();

		new Thread(new Runnable() {

			@Override
			public void run() {
				Message message = new Message();
				message.what = UpImage(selectedAvatar);
				handlerUpload.sendMessage(message);

			}
		}).start();
	}

	private Handler handlerUpload = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			progressDialog.dismiss();

			if (msg.what == GlobalVariables.ReOK) {
				doAddPost();
			} else {
				CommonHelper.showWarning(APostItemDetails.this,
						getString(R.string.disconnect));
			}

		};
	};

	public void startCallServiceAddPost() {
		progressDialog.setMessage(getString(R.string.pleasewait));
		progressDialog.show();

		new Thread(new Runnable() {

			@Override
			public void run() {
				Message message = new Message();
				message.obj = callServiceAddPost();
				handlerAddPost.sendMessage(message);

			}
		}).start();
	}

	private Handler handlerAddPost = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			progressDialog.dismiss();

			if (msg.obj != null) {
				AddPostResponse response = (AddPostResponse) msg.obj;
				if (response.getErrorCode() != null) {
					CommonHelper.showWarning(APostItemDetails.this, response
							.getErrorCode().getErrMsg());
				} else {
					CommonHelper.showWarning(APostItemDetails.this,
							"Successful!");
					tv_post_title.setText(getString(R.string.post_title));
					tv_post_price.setText(getString(R.string.post_price));
					tv_post_exp.setText(getString(R.string.post_expiration));
					tv_post_desc.setText(getString(R.string.post_desc));
					tv_post_category.setText(getString(R.string.post_category));
					img_post_img.setImageBitmap(CommonHelper
							.getRoundedCornerBitmap(bitmap,
									APostItemDetails.this));
					status = 0;
					post_exp = 0;
					post_category = 0;
					post_title = "";
					post_price = "";
					post_desc = "";

				}

			} else {
				CommonHelper.showWarning(APostItemDetails.this,
						getString(R.string.disconnect));
			}

		};
	};

	private void doAddPost() {
		if (CommonHelper.isNetworkAvailable(this)) {
			startCallServiceAddPost();
		} else
			CommonHelper.showWarning(APostItemDetails.this,
					getString(R.string.netstate));
	}

	private AddPostResponse callServiceAddPost() {

		SoapObject userRequest = new SoapObject(GlobalVariables.WS_NAMESPACE,
				GlobalVariables.WS_METHOD_ADD_POST);
		userRequest.addProperty("user_id",
				CommonHelper.getUserLogin(APostItemDetails.this).getId());
		userRequest.addProperty("title", post_title);
		userRequest.addProperty("description", post_desc);
		userRequest.addProperty("price", post_price);
		userRequest.addProperty("expired", post_exp);
		userRequest.addProperty("longitude", CommonHelper.getPosition(this)
				.getLon());
		Log.d("lon", CommonHelper.getPosition(this).getLon());
		userRequest.addProperty("latitude", CommonHelper.getPosition(this)
				.getLat());
		Log.d("lat", CommonHelper.getPosition(this).getLat());
		userRequest.addProperty("imgLink", imageSrc);
		userRequest.addProperty("category_id", post_category);

		SoapObject request = new SoapObject(GlobalVariables.WS_NAMESPACE,
				GlobalVariables.WS_METHOD_ADD_POST);
		request.addProperty(GlobalVariables.WS_METHOD_ADD_POST, userRequest);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);

		HttpTransportSE androidHttpTransport = new HttpTransportSE(
				GlobalVariables.WS_ENDPOINT,
				GlobalVariables.WS_CONNECTTION_TIME_OUT);
		SoapObject results = null;
		try {
			androidHttpTransport.call(GlobalVariables.WS_NAMESPACE
					+ GlobalVariables.WS_METHOD_ADD_POST, envelope);
		} catch (Exception e) {
			try {
				androidHttpTransport.call(GlobalVariables.WS_NAMESPACE
						+ GlobalVariables.WS_METHOD_ADD_POST, envelope);
			} catch (Exception e1) {
				e1.printStackTrace();
				return null;

			}
		}
		try {
			results = (SoapObject) envelope.getResponse();
		} catch (SoapFault ex3) {
			ex3.printStackTrace();
			return null;
		}

		return new AddPostResponse(results);

	}

	// position
	public void setPosition() {
		LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		Location loc = mlocManager
				.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		LocationListener mlocListener = new MyLocationListener(
				APostItemDetails.this);

		mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
				mlocListener);
		if (loc != null) {
			Position pos = new Position();
			pos.setLon(String.valueOf(loc.getLongitude()));
			pos.setLat(String.valueOf(loc.getLatitude()));
			CommonHelper.setPosition(pos, this);
			// CommonHelper.showToast(this, ""
			// + CommonHelper.getPosition(this).getLon() + " "
			// + CommonHelper.getPosition(this).getLat());
			Log.d("LastKnowLocation", ""
					+ CommonHelper.getPosition(this).getLon() + " "
					+ CommonHelper.getPosition(this).getLat());
		} 
		// else {
		// Position pos = new Position();
		// if (CommonHelper.getPosition(this).getLon().equals("")
		// || CommonHelper.getPosition(this).getLat().equals("")) {
		// pos.setLon(String.valueOf(GlobalVariables.lon));
		// pos.setLat(String.valueOf(GlobalVariables.lat));
		// CommonHelper.setPosition(pos, this);
		// }
		//
		// CommonHelper.showToast(this, ""
		// + CommonHelper.getPosition(this).getLon() + " "
		// + CommonHelper.getPosition(this).getLat());
		// }
	}

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	
	public void setMap() {
		GeoP = new GeoPoint((int) (Double.parseDouble(CommonHelper.getPosition(APostItemDetails.this).getLat()) * 1E6),
				(int) (Double.parseDouble(CommonHelper.getPosition(APostItemDetails.this).getLon()) * 1E6));

		OverlayItem item = new OverlayItem(new GeoPoint(
				(int) (Double.parseDouble(CommonHelper.getPosition(APostItemDetails.this).getLat()) * 1E6),
				(int) (Double.parseDouble(CommonHelper.getPosition(APostItemDetails.this).getLon()) * 1E6)), "", "");
		mapOverlays = mapV.getOverlays();
		items = this.getResources().getDrawable(R.drawable.pin_want);
		itemizedOverlay = new MyItemizedOverlay(items, mapV);
		itemizedOverlay.addOverlay(item);
		mapOverlays.add(itemizedOverlay);
		mapV.postInvalidate();

		mControl = mapV.getController();
		mControl.animateTo(GeoP);
		mControl.setZoom(15);
		// mapV.invalidate();
	}
}
